/**
 * controller_withdraw.js
 * 提现控制器
 * 
 * @author  王中艺 <wangzy_smile@qq.com>
 * @date    2017-08-28
 */

app.controller('WithdrawList', function($scope, $http, common){
    //变量声明
    $scope.list     = new Array();
    $scope.nImte    = new Object();
    $scope.nPage    = 1;
    $scope.pageHtml     = '';
    $scope.loading  = false;
    $scope.condition    = {
        keyword     : '',
        date_start  : '',
        date_end    : '',
        status  : ''
    }

    //初始化JS
    $scope.init_js  = function(){
        //标签页钩子设置
        $('a[data-toggle="tab"]').on('show.bs.tab', function(e){
            var type    = $(this).data('target');
            switch(type){
                case '#list-all'    : $scope.condition.status = ''; break;
                case '#list-audit-first' : $scope.condition.status = 2; break;
                case '#list-audit-second': $scope.condition.status = 3; break;
                case '#list-audit-pass': $scope.condition.status = 1; break;
                case '#list-audit-fail': $scope.condition.status = 0; break;
                default: return false; break;
            }
            $scope.get_list(1);
        });

        $('.input-date').datetimepicker({
            language:  'zh-CN',
            format: 'yyyy-mm-dd',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1,
            minView : 2
        });

        //回车键监听
        common.listenEnterKey(function(){
            $scope.get_list(1);
        });
    }

    //加载列表
    $scope.get_list     = function(page){
        var page    = page ? page : 1;
        var url     = config.prefix_url + '/Withdraw/getList?p='+page;
        var param   = {
            condition   : $scope.condition
        }

        $http.post(url, param).success(function(info){
            console.log(info);
            $scope.loading  = false;
            if(info.code != 1){
                common.dealError(info);
                return false;
            }

            $scope.nPage    = page;
            $scope.pageHtml     = info.data.page_html;
            $scope.list     = info.data.list;
            common.startPage($scope.get_list);
        })

        $scope.loading  = true;
    }

    //详情查看
    $scope.get_item     = function(item, modal){
        var modal   = modal ? modal : '.modal.get-item';
        $scope.nItem    = item;
        if(!$scope.nItem.result){
            $scope.nItem.result     = 0;
        }
        $(modal).modal('show');
    }

    //初审条目
    $scope.first_audit  = function(item){
        let url     = config.prefix_url + '/Withdraw/firstAudit';
        let param   = item;

        $http.post(url, param).success(function(info){
            console.log(info);
            $scope.loading  = false;
            if(info.code != 1){
                common.dealError(info);
                return false;
            }
            $scope.get_list($scope.nPage);
            $('.first-audit-item').modal('hide');
        })

        $scope.loading  = true;
    }

    //复审条目
    $scope.second_audit  = function(item){
        let url     = config.prefix_url + '/Withdraw/secondAudit';
        let param   = item;

        $http.post(url, param).success(function(info){
            console.log(info);
            $scope.loading  = false;
            if(info.code != 1){
                common.dealError(info);
                return false;
            }
            $scope.get_list($scope.nPage);
            $('.second-audit-item').modal('hide');
        })

        $scope.loading  = true;
    }

    $scope.get_list(1);
    $scope.init_js();
})